<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="${pageContext.request.contextPath}/css/main.css"
	rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/css/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/css/themes/icon.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.6.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>


<script type="text/javascript">
	var editingId;

	$(function() {
		$('#nameList').panel({
			href : '${pageContext.request.contextPath}/UserController/getUserList',
			fit : true
		});

		$('#ruleDataGrid').treegrid({
			url : '',
			singleSelect : true,
			toolbar : '#toolbar',
			fitColumns : true,
			width : '700px',
			rownumbers : true,
			fit : true,
			idField : 'treeId',
			treeField : 'ruleName',
			columns : [ [ {
				field : 'ruleName',
				title : '模块名称',
				width : '200px'
			}, {
				field : "userId",
				hidden : true
			}, {
				field : 'isCanAdd',
				title : '新增',
				width : '100px',
				editor : {
					type : 'combobox',
					options : {
						valueField : 'value',
						textField : 'text',
						data : [ {
							'value' : '0',
							'text' : '0'
						}, {
							'value' : '1',
							'text' : '1'
						} ],

						panelHeight : 'auto',
						mode : 'remote',
						//required:true,
						editable : false

					}
				},
				formatter : function(value, row, index) {
					var str = '';
					if (row.url != '#') {

						if (value == 0) {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/ok.png" />';
						} else {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/no.png"/>';
						}
						return str;
					}
				}
			}, {
				field : 'isCanEdit',
				title : '修改',
				width : '100px',
				editor : {
					type : 'combobox',
					options : {
						valueField : 'value',
						textField : 'text',
						data : [ {
							'value' : '0',
							'text' : '0'
						}, {
							'value' : '1',
							'text' : '1'
						} ],

						panelHeight : 'auto',
						mode : 'remote',
						//required:true,
						editable : false

					}
				},
				formatter : function(value, row, index) {
					var str = '';
					if (row.url != '#') {
						if (value == 0) {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/ok.png" />';
						} else {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/no.png"/>';
						}
					}
					return str;

				}
			}, {
				field : 'isCanView',
				title : '查看',
				width : '100px',
				editor : {
					type : 'combobox',
					options : {
						valueField : 'value',
						textField : 'text',
						data : [ {
							'value' : '0',
							'text' : '0'
						}, {
							'value' : '1',
							'text' : '1'
						} ],

						panelHeight : 'auto',
						mode : 'remote',
						//required:true,
						editable : false

					}
				},
				formatter : function(value, row, index) {
					var str = '';
					if (row.url != '#') {
						if (value == 0) {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/ok.png" />';
						} else {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/no.png"/>';
						}
					}
					return str;

				}
			}, {
				field : 'isCanDelete',
				title : '删除',
				width : '100px',
				editor : {
					type : 'combobox',
					options : {
						valueField : 'value',
						textField : 'text',
						data : [ {
							'value' : '0',
							'text' : '0'
						}, {
							'value' : '1',
							'text' : '1'
						} ],

						panelHeight : 'auto',
						mode : 'remote',
						//required:true,
						editable : false

					}
				},
				formatter : function(value, row, index) {
					var str = '';
					if (row.url != '#') {
						if (value == 0) {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/ok.png" />';
						} else {
							str += '<img src="${pageContext.request.contextPath}/css/themes/icons/no.png"/>';
						}
					}
					return str;

				}
			} ] ],
			onDblClickCell : function(field, row) {
				if (editingId != undefined) {
					$('#ruleDataGrid').treegrid('select', editingId);
					return;
				}

				if (row.url == '#') {
					return;
				}
				editingId = row.treeId;
				console.info("双击开始");
				console.info(row);
				$(this).treegrid('beginEdit', editingId);
				var ed = $(this).treegrid('getEditors', editingId);
				
				$(ed.target).focus();
			}

		});
	})

	function cancel() {
		var row = $('#ruleDataGrid').treegrid('getSelected');
		if (row != null) {
			$('#ruleDataGrid').treegrid('cancelEdit', editingId);
		}
		editingId = undefined;
	}

	function save() {
		
		$('#ruleDataGrid').datagrid('endEdit', editingId);
		row = $('#ruleDataGrid').treegrid('getSelected');
		
		$.get('${pageContext.request.contextPath}/RuleController/editUserRule', {
			treeId : row.treeId,
			userId : row.userId,
			isCanView : row.isCanView,
			isCanAdd : row.isCanAdd,
			isCanDelete : row.isCanDelete,
			isCanEdit : row.isCanEdit
		}, function(result) {
			if (result.success) {
				parent.$.messager.alert('提示', result.msg, 'info');
				$('#ruleDataGrid').treegrid('reload');
				
			}
			parent.$.messager.progress('close');
			editingId=undefined;
		}, 'JSON');
	}
</script>
</head>
<body>

	<div id="rulelayout" class="easyui-layout" style="height: 550px">
		<div
			data-options="region:'west',title:'用户列表',split:false,collapsible:false"
			style="width: 150px;">
			<div id="nameList" class="easyui-panel"></div>

		</div>
		<div data-options="region:'center',title:'权限内容'"
			style="background: #eee;" >
			<table id="ruleDataGrid" class="easyui-treegrid"></table>
			<div id="toolbar">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-ok" plain="true" onclick="newMeetingRoom()">一键启用</a>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-no" plain="true" onclick="editMeetingRoom()">一键禁用</a>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-save" plain="true" onclick="save()">保存</a> <a
					href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-cancel" plain="true" onclick="cancel()">取消</a>

			</div>


		</div>
	</div>




</body>
</html>